package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anotion.AutoFill;
import com.sky.anotion.AutoId;
import com.sky.dto.common.QueryParams;
import com.sky.entity.Department;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DepartmentMapper {

    /** 根据部门id查询子部门 */
    @Select("select * from department where pid = #{id} ")
    List<Department> getDepartmentsByPid(String id);
    /**新增部门*/
    @AutoFill(value = OperationType.INSERT)
    @AutoId
    void addDepartment(Department departmentAddDTO);
    /**删除部门*/
    @Delete("delete from department where id = #{id}")
    void deleteDepartmentByIds(String id);
    /** 更新部门信息*/
    void updateDepartment(Department department);
    /**查询单个部门id，用户信息时候拼凑返回*/
    @Select("select * from department where id = #{id} and is_use = 1")
    Department getDepartmentById(String id);

    /**
     * 分页获取部门列表
     * @param params
     * @return
     */
    List<Department> getDicDataAll(QueryParams params);

    /**
     * 获取当前部门的下一级数量
     */
    @Select("SELECT COUNT(*) FROM department WHERE pid = #{id}")
    Long getTopLevelDepartmentCount(String id);
    /**
     * 获取一级部门的
     */
    @Select("SELECT * FROM department WHERE( pid IS NULL OR pid = '' )")
    List<Department> getDepartmentPrent();

    /**
     * 获取所有部门列表
     * @return 返回list集合
     */
    List<Department> getDicDataAllList(QueryParams params);

    /**
     * 删除部门负责人信息
     * @param id 部门负责人的id
     */
    @Update("UPDATE department SET instructor_id = null,department_leader = null WHERE instructor_id = #{id}")
    void deleteDepartmentLeader(String id);

    /**
     * 修改部门状态- 包括下属的不部门启用的一个状态
     * @param ids
     * @param status
     */
    void updateDepartmentStatus(List<String> ids, Integer status);
}
